package com.hdsx.jxcsxm.tjbb.server.impl;




import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.hdsx.jxcsxm.tjbb.bean.Bkzh;
import com.hdsx.jxcsxm.tjbb.bean.Plan_upload;
import org.springframework.stereotype.Service;

import com.hdsx.dao.query.base.BaseOperate;
import com.hdsx.jxcsxm.tjbb.bean.Excel_list;
import com.hdsx.jxcsxm.tjbb.server.SbzjServer;
import com.hdsx.jxcsxm.tjbb.server.TjbbServer;
import com.hdsx.jxcsxm.xtgl.bean.TreeNode;
import com.hdsx.jxcsxm.xtgl.bean.Xmjbxx;



@Service
public class SbzjServerImpl extends BaseOperate  implements SbzjServer{

	public SbzjServerImpl() {
		super("tjbb", "jdbc");
	}

	@Override
	public List<Xmjbxx> autoxmmc(String trim) {
		return queryList("autoxmmc",trim);
	}
	@Override
	public List<Xmjbxx> autoNoticeName(String trim) {
		return queryList("autoNoticeName",trim);
	}

	@Override
	public List<Xmjbxx> autohm(String trim) {
		return queryList("autohm",trim);
	}

	@Override
	public List<Xmjbxx> queryysqlist(Xmjbxx xmjbxx) {
		return queryList("queryysqlist",xmjbxx);
	}

	@Override
	public int queryysqlistCount(Xmjbxx xmjbxx) {
		return queryOne("queryysqlistCount", xmjbxx);
	}
	
	@Override
	public List<Xmjbxx> querysbzjsj(Xmjbxx xmjbxx) {
		return queryList("querysbzjsj",xmjbxx);
	}
	@Override
	public boolean delsqmx(Xmjbxx xmjbxx) {
		return delete("delsqmx", xmjbxx)>0;
	}
	@Override
	public boolean checkNameCf(Xmjbxx xmjbxx) {
		int i=queryOne("checkNameCf", xmjbxx);
		if(i>0){
			 return true;
		}else{
			return false;
		}
	}
	
	@Override
	public boolean insertSbzjsq(Xmjbxx xmjbxx) {
		//查询是否已存在
		Xmjbxx x=queryOne("getsbzjZbById", xmjbxx);
		if(x!=null) {
			//修改主表
			update("updateSbzjsq", xmjbxx);
			//添加子表
			if(!"".equals(xmjbxx.getBcje()))
			insert("insertSbzjsqmx", xmjbxx);
			update("updateZhjhje",xmjbxx);
		}else {
			insert("insertSbzjsq", xmjbxx);
			if(!"".equals(xmjbxx.getBcje()))
			insert("insertSbzjsqmx", xmjbxx);
			update("updateZhjhje",xmjbxx);
		}
		return true;
	}

	@Override
	public boolean insertNotice(Xmjbxx xmjbxx) {
		//查询是否已存在
		Xmjbxx x=queryOne("getNoticeById", xmjbxx);
		if(x!=null) {
			//修改主表
			update("updateNotice", xmjbxx);
		}else {
			insert("insertNotice", xmjbxx);
		}
		return true;
	}

	@Override
	public boolean insertDfzczjlr(Xmjbxx xmjbxx) {
		//查询是否已存在
		Xmjbxx x=queryOne("getDfzczjlrByJhidAndZhidAndXmlx", xmjbxx);
		if(x!=null) {
			update("updateDfzczjlr", xmjbxx);
		}else {
			insert("insertDfzczjlr", xmjbxx);
		}
		return true;
	}

	@Override
	public boolean updateSbzjsqMx(Xmjbxx xmjbxx) {
		//查询是否已存在
		
			int i=update("updateSbzjsqMx", xmjbxx);
			int j=update("updateSbzjsqMxZhjhje", xmjbxx);
			System.out.println(i+"::::"+j);
		return true;
	}
	@Override
	public boolean updateSbzjsq(Xmjbxx xmjbxx) {
		update("updateSbzjsq", xmjbxx);
		return true;
	}
	@Override
	public List<Xmjbxx> selectsbzjList(Xmjbxx xmjbxx) {
		return queryList("selectsbzjList", xmjbxx);
	}
	@Override
	public List<Xmjbxx> selectNoticeList(Xmjbxx xmjbxx) {
		return queryList("selectNoticeList", xmjbxx);
	}

	@Override
	public int selectsbzjListCount(Xmjbxx xmjbxx) {
		return queryOne("selectsbzjListCount", xmjbxx);
	}
	@Override
	public int selectNoticeListCount(Xmjbxx xmjbxx) {
		return queryOne("selectNoticeListCount", xmjbxx);
	}
	@Override
	public List<Xmjbxx> selectDfzczjlrList(Xmjbxx xmjbxx) {
		return queryList("selectDfzczjlrList", xmjbxx);
	}

	@Override
	public int selectDfzczjlrListCount(Xmjbxx xmjbxx) {
		return queryOne("selectDfzczjlrListCount", xmjbxx);
	}

	@Override
	public List<Xmjbxx> selectZjqkdwdzbList(Xmjbxx xmjbxx) {
		return queryList("selectZjqkdwdzbList", xmjbxx);
	}

	@Override
	public List<Excel_list> exportZjqkdwdzbList(Excel_list elist) {
		return queryList("exportZjqkdwdzbList", elist);
	}

	@Override
	public int selectZjqkdwdzbListCount(Xmjbxx xmjbxx) {
		return queryOne("selectZjqkdwdzbListCount", xmjbxx);
	}

	@Override
	public boolean delsq(Xmjbxx xmjbxx) {
		delete("delsqbyid", xmjbxx);
		delete("delsqmxbyid", xmjbxx);

		delete("delFileByParentid", xmjbxx);
		delete("delFileRelationByXmbm", xmjbxx);
		return true;
	}
	@Override
	public boolean delNotice(Xmjbxx xmjbxx) {
		delete("delNotice", xmjbxx);
		delete("delNoticeOfFile", xmjbxx);
		return true;
	}

	@Override
	public List<Xmjbxx> getSbzjById(Xmjbxx xmjbxx) {
		return queryList("getSbzjById", xmjbxx);
	}

	@Override
	public Xmjbxx selectsbzjByzhid(Xmjbxx xmjbxx) {
		// TODO Auto-generated method stub
		return queryOne("selectsbzjByzhid", xmjbxx);
	}

	@Override
	public Xmjbxx sumye(Xmjbxx xmjbxx) {
		// TODO Auto-generated method stub
		return queryOne("selectsumye", xmjbxx);
	}
	@Override
	public Xmjbxx sumyeByBJID(Xmjbxx xmjbxx) {
		// TODO Auto-generated method stub
		return queryOne("selectsumyeByBJID", xmjbxx);
	}



	@Override
	public Plan_upload queryFileByWh(Plan_upload uploads) {
		//System.out.println(uploads.getFiletype()+"   "+uploads.getFilewh()+"    "+uploads.getFilename());
		return queryOne("queryFileByWh", uploads);
	}
	@Override
	public boolean insertFileJl(Plan_upload uploads) {
		return insert("insertFileJl", uploads)>0;
	}

	@Override
	public boolean insertFile(Plan_upload uploads) {
		return insert("insertFile", uploads)>0;
	}

	@Override
	public List<Plan_upload> queryFjByParentId(Plan_upload uploads) {
		return queryList("queryFjByParentId",uploads);
	}
	@Override
	public List<Plan_upload> queryNoticeFjByParentId(Plan_upload uploads) {
		return queryList("queryNoticeFjByParentId",uploads);
	}

	@Override
	public boolean deleteFile(Plan_upload uploads) {
		if("ggwj".equals(uploads.getFiletype())){
			return delete("deleteFileUpload", uploads)>0 ? true:false;
		}else{
			delete("deleteFileUpload", uploads);
			return delete("deleteFile", uploads)>0 ? true:false;
		}

	}

	@Override
	public boolean insertSbzjList(Xmjbxx xmjbxx,List<Map> data) {
		//查询是否已存在
		//Xmjbxx x = queryOne("getDfzczjlrByJhidAndZhidAndXmlx", xmjbxx);
		                     
			boolean insertBatch = insertBatch("insertSbzjsqmxList", data) == data.size();
			if (insertBatch) {
				insert("insertSbzjsq", xmjbxx);
				return true;
			}
		return true;
	}

	@Override
	public List<Xmjbxx> exportqklrmbdc(Xmjbxx xmjbxx) {
		return queryList("exportqklrmbdc", xmjbxx);
	}

	@Override
	public boolean importqklr(List<Map> data) {
		return insertBatch("importqklr", data)==data.size();
	}

	@Override
	public Bkzh autosbzjhmNcgl(String xmdj) {
		return queryOne("autocgshmNcgl",xmdj);
	}

	@Override
	public Bkzh autosbzjhmGsd(String xmdj) {
		return queryOne("autocgshmGsd",xmdj);
	}
}
